package com.iwuke.dance.gadget_view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.iwuke.dance.R;

import androidx.annotation.Nullable;

/**
 * @author: 魏从响
 * @date: 2025/9/24
 */
public class DefaultView extends LinearLayout implements View.OnClickListener {

    private ImageView img_default;
    private TextView tv_default_desc;
    private TextView tv_default_button;
    private OnClickListener onDefaultButtonClick;

    public DefaultView(Context context) {
        super(context);
    }

    public DefaultView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_default, this);

        img_default = inflate.findViewById(R.id.img_default);
        tv_default_desc = inflate.findViewById(R.id.tv_default_desc);
        tv_default_button = inflate.findViewById(R.id.tv_default_button);

        tv_default_button.setOnClickListener(this);
    }

    public DefaultView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setImageView(int color){
        img_default.setImageResource(color);
    }

    public void setTextView(String default_desc){
        tv_default_desc.setText(default_desc);
    }

    public void setButtonVisibility(boolean buttonVisibility){
        if (buttonVisibility){
            tv_default_button.setVisibility(VISIBLE);
        }else {
            tv_default_button.setVisibility(GONE);
        }
    }

    public void setOnDefaultButtonClick(OnClickListener onDefaultButtonClick){

        this.onDefaultButtonClick = onDefaultButtonClick;
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.tv_default_button){
            if (onDefaultButtonClick!=null)
                onDefaultButtonClick.onClick(v);
        }
    }
}

